﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RuleCode.compiler;
using EnvDTE;
using System.IO;

namespace RuleCode.ObjectTree
{
    public partial class WebFormsContextMenu : CompileContextMenu
    {
        public WebFormsContextMenu()
        {
            InitializeComponent();
            CustInit();
        }
        //private System.Windows.Forms.ToolStripMenuItem addWebFormToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem SingleToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem MasterSlaveToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem realToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem dateToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem timeToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem enumToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem containerToolStripMenuItem;
        //private System.Windows.Forms.ToolStripMenuItem int64ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem sycToDBToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem synToolStripMenuItem;
        private void CustInit()
        {
            this.sycToDBToolStripMenuItem = new ToolStripMenuItem();
            //this.addWebFormToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.SingleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.MasterSlaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.realToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.dateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.timeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.enumToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.containerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            //this.int64ToolStripMenuItem = new ToolStripMenuItem();
            this.SuspendLayout();
            // 
            // addWebFormToolStripMenuItem
            // 
            //this.addWebFormToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            //this.SingleToolStripMenuItem,
            //this.MasterSlaveToolStripMenuItem,
            //this.realToolStripMenuItem,
            //this.dateToolStripMenuItem,
            //this.timeToolStripMenuItem,
            //this.enumToolStripMenuItem,
            //this.containerToolStripMenuItem,
            //this.int64ToolStripMenuItem});
            //this.addWebFormToolStripMenuItem.Name = "addWebFormToolStripMenuItem";
            //this.addWebFormToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            //this.addWebFormToolStripMenuItem.Text = "新建WebForm";

            this.sycToDBToolStripMenuItem.Name="SycToDB";
            this.sycToDBToolStripMenuItem.Size = new Size(152,22);
            this.sycToDBToolStripMenuItem.Text  = "同步";
            this.sycToDBToolStripMenuItem.Click += new EventHandler(sycToDBToolStripMenuItem_Click);
            // 
            // SingleToolStripMenuItem
            // 
            ////this.SingleToolStripMenuItem.Name = "SingleToolStripMenuItem";
            ////this.SingleToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            ////this.SingleToolStripMenuItem.Text = "Single";
            ////this.SingleToolStripMenuItem.Click += new System.EventHandler(this.SingleToolStripMenuItem_Click);
            ////// 
            ////// MasterSlaveToolStripMenuItem
            ////// 
            ////this.MasterSlaveToolStripMenuItem.Name = "MasterSlaveToolStripMenuItem";
            ////this.MasterSlaveToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            ////this.MasterSlaveToolStripMenuItem.Text = "Multi";
            ////this.MasterSlaveToolStripMenuItem.Click += new System.EventHandler(this.MasterSlaveToolStripMenuItem_Click);
            ////// 
            ////// realToolStripMenuItem
            ////// 
            ////this.realToolStripMenuItem.Name = "realToolStripMenuItem";
            ////this.realToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            ////this.realToolStripMenuItem.Text = "Real";
            ////this.realToolStripMenuItem.Click += new System.EventHandler(this.realToolStripMenuItem_Click);
            ////// 
            ////// dateToolStripMenuItem
            ////// 
            ////this.dateToolStripMenuItem.Name = "dateToolStripMenuItem";
            ////this.dateToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            ////this.dateToolStripMenuItem.Text = "Date";
            ////this.dateToolStripMenuItem.Click += new System.EventHandler(this.dateToolStripMenuItem_Click);
            ////// 
            ////// timeToolStripMenuItem
            ////// 
            ////this.timeToolStripMenuItem.Name = "timeToolStripMenuItem";
            ////this.timeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            ////this.timeToolStripMenuItem.Text = "Time";
            ////this.timeToolStripMenuItem.Click += new System.EventHandler(this.timeToolStripMenuItem_Click);
            ////// 
            ////// enumToolStripMenuItem
            ////// 
            ////this.enumToolStripMenuItem.Name = "enumToolStripMenuItem";
            ////this.enumToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            ////this.enumToolStripMenuItem.Text = "Enum";
            ////this.enumToolStripMenuItem.Click += new System.EventHandler(this.enumToolStripMenuItem_Click);
            ////// 
            ////// containerToolStripMenuItem
            ////// 
            ////this.containerToolStripMenuItem.Name = "containerToolStripMenuItem";
            ////this.containerToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            ////this.containerToolStripMenuItem.Text = "Container";
            ////this.containerToolStripMenuItem.Click += new System.EventHandler(this.containerToolStripMenuItem_Click);
            ////// 
            ////this.int64ToolStripMenuItem.Name = "int64ToolStripMenuItem";
            ////this.int64ToolStripMenuItem.Size = new Size(152, 22);
            ////this.int64ToolStripMenuItem.Text = "Int64";
            ////this.int64ToolStripMenuItem.Click += new System.EventHandler(int64ToolStripMenuItem_Click);
            ////// EDTContextMenu
            ////// 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.Name = "WebFormsContextMenu";
            this.ResumeLayout(false);
            base.baseContextMenuStrip.Items.Insert(4, sycToDBToolStripMenuItem);

        }

        void sycToDBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            //base.sycToDBToolStripMenuItem_Click(sender, e);
            //删除已有数据
            SqlHelper.Instance.ExecuteNonQuery(CommandType.Text, "Delete  from MenuItem");
            foreach (SysTreeNode node in Util.SelectedNode.Nodes)
            {
                node.ExpandAll();
                foreach (SysTreeNode subNode in node.Nodes)
                {
                    int type = 0;
                    subNode.ExpandAll();
                    if (node.Text == "WebFormSingle")
                    {
                        type = 0;
                    }
                    if (node.Text == "WebFormMasterSlave")
                    {
                        type = 1;
                    }
                    if (node.Text == "WebFormTree")
                    {
                        type = 2;
                    }
                    if (node.Text == "WebFormParameter")
                    {
                        type = 3;
                    }
                    if (node.Text == "WebFormParaByUser")
                    {
                        type = 4;
                    }
                    if (node.Text == "WebFormRelation")
                    {
                        type = 5;
                    }
                    Util.SetPropertyContent(subNode);
                    SqlHelper.Instance.ExecuteNonQuery(CommandType.Text,
                      "INSERT INTO  [dbo].[MenuItem] ([DATAAREAID] ,[RECID],[MenuItemID],[MenuItemType],[Name]" +
                      ",[ObjectType],[ObjectName]" +
                      " ,[Label],[ModuleName]) VALUES('" + "" + "', "
                      + Convert.ToString(Util.GetNewRecId)
                      +
                      ", '" +
                      subNode.Property.ID + "' ," + type + " ,'" + subNode.Text +
                      "' ," + 0 + " ,'" +
                      "" + "' ,'" +
                      ((WebFormProperty)subNode.Property).Label + "' ,'" + "" +
                      "')");
                }
            }

        }
         protected override void CompileNode()
        {
            base.CompileNode();
           // SysCompiler.Instance.compileEDTs(Util.SelectedNode);
        }

     

        private void SingleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(WebFormSingleProperty));
        }

        private void MasterSlaveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(WebFormMasterSlaveProperty));
        }
        private void int64ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(EDTInt64Property));
        }

        private void realToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(EDTRealProperty));
        }

        private void dateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(EDTDateProperty));
        }

        private void timeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(EDTTimeProperty));
        }

        private void enumToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(EDTEnumProperty));
        }

        private void containerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addWebForm(typeof(EDTContainerProperty));
        }

        private void addWebForm(Type type)
        {

            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebForms, OT.WebForm,
                                       type, "");
        }
    }
    public  class BaseWebFormsContextMenu : NewAndCompileContext
    {
        public BaseWebFormsContextMenu()
        {
            InitializeComponent();

        }
        #region Design
        /// <summary> 
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源，为 true；否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region 组件设计器生成的代码

        /// <summary> 
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        }

        #endregion
        #endregion 


    }
    public class BaseWebFormContextMenu : DeleteAndCompileContextMenu
    {
        /// <summary>
        /// 删除在项目中的文件
        /// </summary>
        protected virtual void DeleteFileInSolution()
        { 
        }

        public BaseWebFormContextMenu()
        {
           
            OnAfterNodeDelete += new DeleteNodeEventHandler(WebFormContextMenu_OnAfterNodeDelete);
        }

        void WebFormContextMenu_OnAfterNodeDelete(object sender, DeleteNodeEventArgs e)
        {
            //if (e.treeNode.Property == null)
            //{
            //    Util.SetProerptyInSilent(e.treeNode);
            //}
            //string id = e.treeNode.Property.ID;
            //string name = e.treeNode.Text;
            //FileInfo file = new FileInfo(Util.GetFormsPath + "\\" + name + ".cs");     //Util.OTPath + @"\Module\Forms" 
            //if (file.Exists)
            //{
            //    file.Delete();
            //}
            //FileInfo designFile = new FileInfo(Util.GetFormsPath + "\\" + name + ".designer.cs");    //Util.OTPath + @"\Module\Forms" 
            //if (designFile.Exists)
            //{
            //    designFile.Delete();
            //}

            ////FileInfo queryFile = new FileInfo(Util.GetQueriesPath +"\\" + id + ".cs"); //Util.OTPath + @"\Module\Queries\"
            ////if (queryFile.Exists)
            ////{
            ////    queryFile.Delete();
            ////}    

            if (Util_DTE.IsAddToProjectAtCompiled)
                DeleteFileInSolution();
        }

        protected override void CompileNode()
        {
            base.CompileNode();
            //SysCompiler.Instance.compileForm(Util.SelectedNode);

        }
    }
    public class WebFormSingleContextMenu : BaseWebFormContextMenu
    {
        protected override void CompileNode()
        {
            base.CompileNode();
            //SysCompiler.Instance.compileForm(Util.SelectedNode);
            SysCompilerWebForm.Instance.compileSingleWebForm(Util.SelectedNode);
        }

        protected override void DeleteFileInSolution()
        {
            base.DeleteFileInSolution();
            if (Util_DTE.IsAddToProjectAtCompiled)
            {
                try
                {
                    if (Util_DTE.AddIn_ApplicationObject != null && Util_DTE.AddIn_ApplicationObject.Solution.Count > 0)
                    {
                        Util.SetProerptyInSilent(Util.SelectedNode);
                        string FormBaseName = Util.SelectedNode .Text;
                        string nodePath = string.Empty;
                        string sourceFileFullName = string.Empty;
                        Project project = null;
                        Struct_GenerateTypePathProject gStruct = Util_DTE.AllGenerateTypePathProjects[GenerateFileType.WebForm];
                        project = gStruct.Project;
                        nodePath = Path.Combine(gStruct.GeneratePath, OT.WebFormSingles);
                        if (project != null)
                        {
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_List" + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_List" + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_List" + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_Edit" + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_Edit" + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_Edit" + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                        }
                    }
                }
                catch (Exception error)
                {
                    Util.SetStatusInfo(error.Message);
                }
            }
        }
    }
    public class WebFormSinglesContextMenu : BaseWebFormsContextMenu
    {
        protected override void addNewNode()
        {
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormSingles, OT.WebFormSingle,
                                      typeof(WebFormSingleProperty), "");
            base.addNewNode();
        }
        protected override void CompileNode()
        {

            base.CompileNode();
        }
    }
    public class WebFormMasterSlaveContextMenu : BaseWebFormContextMenu
    {
        protected override void CompileNode()
        {
            base.CompileNode();
            //SysCompiler.Instance.compileForm(Util.SelectedNode);
            SysCompilerWebForm.Instance.compileMasterSlaveWebForm(Util.SelectedNode);
        }

        protected override void DeleteFileInSolution()
        {
            base.DeleteFileInSolution();
            if (Util_DTE.IsAddToProjectAtCompiled)
            {
                try
                {
                    if (Util_DTE.AddIn_ApplicationObject != null && Util_DTE.AddIn_ApplicationObject.Solution.Count > 0)
                    {
                        Util.SetProerptyInSilent(Util.SelectedNode);
                        string FormBaseName = Util.SelectedNode .Text ;
                        string nodePath = string.Empty;
                        string sourceFileFullName = string.Empty;
                        Project project = null;
                        Struct_GenerateTypePathProject gStruct = Util_DTE.AllGenerateTypePathProjects[GenerateFileType.WebForm];
                        project = gStruct.Project;
                        nodePath = Path.Combine(gStruct.GeneratePath, OT.WebFormMasterSlaves );
                        if (project != null)
                        {
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_MasterList" + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_MasterList" + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_MasterList" + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_SlaveList" + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_SlaveList" + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_SlaveList" + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_SlaveEdit" + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_SlaveEdit" + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + "_SlaveEdit" + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                        }
                    }
                }
                catch (Exception error)
                {
                    Util.SetStatusInfo(error.Message);
                }
            }
        }

    }
    public class WebFormMasterSlavesContextMenu : BaseWebFormsContextMenu
    {
        protected override void addNewNode()
        {
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormMasterSlaves, OT.WebFormMasterSlave,
                                      typeof(WebFormMasterSlaveProperty), "");
            base.addNewNode();
        }
        protected override void CompileNode()
        {

            base.CompileNode();
        }
    }
    public class WebFormTreeContextMenu : BaseWebFormContextMenu
    {
        protected override void CompileNode()
        {
            base.CompileNode();
            //SysCompiler.Instance.compileForm(Util.SelectedNode);
            SysCompilerWebForm.Instance.compileTreeWebForm(Util.SelectedNode);
        }

        protected override void DeleteFileInSolution()
        {
            base.DeleteFileInSolution();
            if (Util_DTE.IsAddToProjectAtCompiled)
            {
                try
                {
                    if (Util_DTE.AddIn_ApplicationObject != null && Util_DTE.AddIn_ApplicationObject.Solution.Count > 0)
                    {
                        Util.SetProerptyInSilent(Util.SelectedNode);
                        string FormBaseName = Util.SelectedNode .Text;
                        string nodePath = string.Empty;
                        string sourceFileFullName = string.Empty;
                        Project project = null;
                        Struct_GenerateTypePathProject gStruct = Util_DTE.AllGenerateTypePathProjects[GenerateFileType.WebForm];
                        project = gStruct.Project;
                        nodePath = Path.Combine(gStruct.GeneratePath, OT.WebFormTrees );
                        if (project != null)
                        {
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName +  ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName +  ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName +  ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);   
                        }
                    }
                }
                catch (Exception error)
                {
                    Util.SetStatusInfo(error.Message);
                }
            }
        }
    }
    public class WebFormTreesContextMenu : BaseWebFormsContextMenu
    {
        protected override void addNewNode()
        {
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormTrees, OT.WebFormTree,
                                      typeof(WebFormTreeProperty), "");
            base.addNewNode();
        }
        protected override void CompileNode()
        {

            base.CompileNode();
        }
    }
    public class WebFormParameterContextMenu : BaseWebFormContextMenu
    {
        protected override void CompileNode()
        {
            base.CompileNode();
            //SysCompiler.Instance.compileForm(Util.SelectedNode);
            SysCompilerWebForm.Instance.compileParameterWebForm(Util.SelectedNode);
        }

        protected override void DeleteFileInSolution()
        {
            base.DeleteFileInSolution();
            if (Util_DTE.IsAddToProjectAtCompiled)
            {
                try
                {
                    if (Util_DTE.AddIn_ApplicationObject != null && Util_DTE.AddIn_ApplicationObject.Solution.Count > 0)
                    {
                        Util.SetProerptyInSilent(Util.SelectedNode);
                        string FormBaseName = Util.SelectedNode .Text;
                        string nodePath = string.Empty;
                        string sourceFileFullName = string.Empty;
                        Project project = null;
                        Struct_GenerateTypePathProject gStruct = Util_DTE.AllGenerateTypePathProjects[GenerateFileType.WebForm];
                        project = gStruct.Project;
                        nodePath = Path.Combine(gStruct.GeneratePath, OT.WebFormParameters );
                        if (project != null)
                        {
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName   + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName   + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName   + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);    
                        }
                    }
                }
                catch (Exception error)
                {
                    Util.SetStatusInfo(error.Message);
                }
            }
        }

    }
    public class WebFormParametersContextMenu : BaseWebFormsContextMenu
    {
        protected override void addNewNode()
        {
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormParameters, OT.WebFormParameter,
                                      typeof(WebFormParameterProperty), "");
            base.addNewNode();
        }
        protected override void CompileNode()
        {

            base.CompileNode();
        }
    }
    public class WebFormParaByUserContextMenu : BaseWebFormContextMenu
    {
        protected override void CompileNode()
        {
            base.CompileNode();
            //SysCompiler.Instance.compileForm(Util.SelectedNode);
            SysCompilerWebForm.Instance.compileParaByUserWebForm(Util.SelectedNode);
        }

        protected override void DeleteFileInSolution()
        {
            base.DeleteFileInSolution();
            if (Util_DTE.IsAddToProjectAtCompiled)
            {
                try
                {
                    if (Util_DTE.AddIn_ApplicationObject != null && Util_DTE.AddIn_ApplicationObject.Solution.Count > 0)
                    {
                        Util.SetProerptyInSilent(Util.SelectedNode);
                        string FormBaseName = Util.SelectedNode .Text;
                        string nodePath = string.Empty;
                        string sourceFileFullName = string.Empty;
                        Project project = null;
                        Struct_GenerateTypePathProject gStruct = Util_DTE.AllGenerateTypePathProjects[GenerateFileType.WebForm];
                        project = gStruct.Project;
                        nodePath = Path.Combine(gStruct.GeneratePath, OT.WebFormParaByUsers );
                        if (project != null)
                        {
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName   + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName   + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName   + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);                 
                        }
                    }
                }
                catch (Exception error)
                {
                    Util.SetStatusInfo(error.Message);
                }
            }
        }

    }
    public class WebFormParaByUsersContextMenu : BaseWebFormsContextMenu
    {
        protected override void addNewNode()
        {
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormParaByUsers, OT.WebFormParaByUser,
                                      typeof(WebFormParaByUserProperty), "");
            base.addNewNode();
        }
        protected override void CompileNode()
        {

            base.CompileNode();
        }
    }
    public class WebFormRelationContextMenu : BaseWebFormContextMenu
    {
        protected override void CompileNode()
        {
            base.CompileNode();
            //SysCompiler.Instance.compileForm(Util.SelectedNode);
            SysCompilerWebForm.Instance.compileRelationWebForm(Util.SelectedNode);
        }

        protected override void DeleteFileInSolution()
        {
            base.DeleteFileInSolution();
            if (Util_DTE.IsAddToProjectAtCompiled)
            {
                try
                {
                    if (Util_DTE.AddIn_ApplicationObject != null && Util_DTE.AddIn_ApplicationObject.Solution.Count > 0)
                    {
                        Util.SetProerptyInSilent(Util.SelectedNode);
                        string FormBaseName = Util.SelectedNode .Text;
                        string nodePath = string.Empty;
                        string sourceFileFullName = string.Empty;
                        Project project = null;
                        Struct_GenerateTypePathProject gStruct = Util_DTE.AllGenerateTypePathProjects[GenerateFileType.WebForm];
                        project = gStruct.Project;
                        nodePath = Path.Combine(gStruct.GeneratePath, OT.WebFormRelations);
                        if (project != null)
                        {
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);                             
                        }
                    }
                }
                catch (Exception error)
                {
                    Util.SetStatusInfo(error.Message);
                }
            }
        }

    }
    public class WebFormRelationsContextMenu : BaseWebFormsContextMenu
    {
        protected override void addNewNode()
        {
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormRelations, OT.WebFormRelation,
                                      typeof(WebFormRelationProperty), "");
            base.addNewNode();
        }
        protected override void CompileNode()
        {

            base.CompileNode();
        }
    }

    public class WebFormFieldGroupsContextMenu : NewNodeContextMenu
    {
        public WebFormFieldGroupsContextMenu()
        {
            
            this.Name = "WebFormFieldGroupsContextMenu";          
            newNodeToolStripMenuItem.Text = "新建字段组";
        }

        protected override void addNewNode()
        {
            base.addNewNode();
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormFieldGroups, OT.WebFormFieldGroup,
                                       typeof(WebFormFieldGroupProperty), "");
        }
    }
    public class WebFormButtonsContextMenu : NewNodeContextMenu
    {
        public WebFormButtonsContextMenu()
        {
            
            this.Name = "WebFormButtonsContextMenu";
           

            newNodeToolStripMenuItem.Text = "新建Button";
        }

        protected override void addNewNode()
        {
            base.addNewNode();
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormButtons, OT.WebFormButton,
                                       typeof(WebFormButtonProperty), "");
        }
    }
    public  class WebFormFieldGroupContextMenu : DeleteContextMenu
    {
        public WebFormFieldGroupContextMenu()
        {
               
        }
        
    }
    public class WebFormButtonContextMenu : DeleteContextMenu
    {
        public WebFormButtonContextMenu()
        {
             
        }
        
    }
    public class WebFormBlankContextMenu : BaseWebFormContextMenu
    {
        protected override void CompileNode()
        {
            base.CompileNode();
            
            SysCompilerWebForm.Instance.compileBlankWebForm(Util.SelectedNode);
        }

        protected override void DeleteFileInSolution()
        {
            base.DeleteFileInSolution();
            if (Util_DTE.IsAddToProjectAtCompiled)
            {
                try
                {
                    if (Util_DTE.AddIn_ApplicationObject != null && Util_DTE.AddIn_ApplicationObject.Solution.Count > 0)
                    {
                        Util.SetProerptyInSilent(Util.SelectedNode);
                        string FormBaseName = Util.SelectedNode.Text;
                        string nodePath = string.Empty;
                        string sourceFileFullName = string.Empty;
                        Project project = null;
                        Struct_GenerateTypePathProject gStruct = Util_DTE.AllGenerateTypePathProjects[GenerateFileType.WebForm];
                        project = gStruct.Project;
                        nodePath = Path.Combine(gStruct.GeneratePath, OT.WebFormRelations);
                        if (project != null)
                        {
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + ".aspx");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + ".aspx.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                            sourceFileFullName = Path.Combine(nodePath, FormBaseName + ".aspx.designer.cs");
                            Util_DTE.DeleteFileInProject(project, sourceFileFullName);
                        }
                    }
                }
                catch (Exception error)
                {
                    Util.SetStatusInfo(error.Message);
                }
            }
        }

    }
    public class WebFormBlanksContextMenu : BaseWebFormsContextMenu
    {
        protected override void addNewNode()
        {
            string name = Util.addNode(OT.XPathRootSeperator + OT.XPathRoot + OT.WebFormBlanks, OT.WebFormBlank,
                                      typeof(WebFormBlankProperty), "");
            base.addNewNode();
        }
        protected override void CompileNode()
        {

            base.CompileNode();
        }
    }


}
